#!/bin/bash

#@File    :   mianmi.sh
#@Time    :   2024/02/16
#@Author  :   Wu ChunLong
#@Version :   1.0
#@Desc    :   None
#@Contact :   13402553918@163.com
# ./mianmi.sh 83418341

password=$1
/usr/bin/expect <<-EOF

spawn ssh-keygen -t rsa
expect {
   "ssh/id_rsa):"
    {send "\n";exp_continue}
   "(y/n)?"
    {send "y\n";exp_continue}
   "passphrase):"
   {send "\n";exp_continue}
   "again:"
   {send "\n";exp_continue}
}
expect eof
EOF



for ip in $(cat host_list)
do

/usr/bin/expect <<-EOF
spawn ssh-copy-id -i $HOME/.ssh/id_rsa.pub  root@$ip
expect {
    "yes/no/"
    {send "yes\n";exp_continue}
    "password:"
    {send "$password\n"}
}
expect eof
EOF

done


